package com.zkkj.demo.vo.base;

import com.zkkj.demo.enume.ErrorEnum;
import com.zkkj.demo.enume.RightEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * author : cyc
 * Date : 2019/12/25
 */

@Data
@ApiModel(value = "返回基类")
public class BaseResultVo<T> extends AResultVo<T> {

    @ApiModelProperty(name = "code", value = "状态码")
    private int code;

    @ApiModelProperty(name = "data", value = "返回数据")
    private T data;

    @ApiModelProperty(name = "desc", value = "描述")
    private String desc = "操作成功";

    public BaseResultVo(int code, String desc, T data) {
        this.code = code;
        this.data = data;
        this.desc = desc;
    }

    public BaseResultVo(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public BaseResultVo() {
    }

    /**
     * 静态方法无法访问类上的定义的泛型，如果静态方法操作的引用数据类型不确定类型，必须将泛型类型定义到方法上
     * 如果要在静态方法上使用泛型，则必须将该方法声明成泛型方法
     *
     * @param t
     * @param <T>
     * @return
     */
    public static <T> AResultVo<T> resultSuccess(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(RightEnum.RES_SUCCESS.getCode(), RightEnum.RES_SUCCESS.getDesc(), t);
        return aResultVo;
    }

    public static <T> AResultVo<T> resultSuccess(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(RightEnum.RES_SUCCESS.getCode(), desc, t);
        return aResultVo;
    }

    @Override
    public AResultVo<T> success(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(RightEnum.RES_SUCCESS.getCode(), RightEnum.RES_SUCCESS.getDesc(), t);
        return aResultVo;
    }

    public AResultVo<T> success(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(RightEnum.RES_SUCCESS.getCode(), desc, t);
        return aResultVo;
    }

    /**
     * 系统异常
     *
     * @param t
     * @return
     */
    public static <T> AResultVo<T> resultFailure(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.SYS_ERROR.getCode(), ErrorEnum.SYS_ERROR.getDesc(), t);
        return aResultVo;
    }

    public static <T> AResultVo<T> resultFailure(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.SYS_ERROR.getCode(), desc, t);
        return aResultVo;
    }


    public AResultVo<T> failure(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.SYS_ERROR.getCode(), ErrorEnum.SYS_ERROR.getDesc(), t);
        return aResultVo;
    }

    @Override
    public AResultVo<T> failure(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.SYS_ERROR.getCode(), desc, t);
        return aResultVo;
    }


    /**
     * 无权选异常
     *
     * @param t
     * @return
     */
    public static <T> AResultVo<T> resultFobidden(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.FORBIDDEN.getCode(), ErrorEnum.FORBIDDEN.getDesc(), t);
        return aResultVo;
    }

    public static <T> AResultVo<T> resultFobidden(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.FORBIDDEN.getCode(), desc, t);
        return aResultVo;
    }

    public AResultVo<T> forbidden(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.FORBIDDEN.getCode(), ErrorEnum.FORBIDDEN.getDesc(), t);
        return aResultVo;
    }

    public AResultVo<T> forbidden(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.FORBIDDEN.getCode(), desc, t);
        return aResultVo;
    }

    /**
     * 鉴权异常
     *
     * @param t
     * @return
     */
    public static <T> AResultVo<T> resultUnauthorized(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.UNAUTHORIZED.getCode(), ErrorEnum.UNAUTHORIZED.getDesc(), t);
        return aResultVo;
    }

    public static <T> AResultVo<T> resultUnauthorized(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.UNAUTHORIZED.getCode(), desc, t);
        return aResultVo;
    }

    public AResultVo<T> unauthorized(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.UNAUTHORIZED.getCode(), ErrorEnum.UNAUTHORIZED.getDesc(), t);
        return aResultVo;
    }

    public AResultVo<T> unauthorized(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.UNAUTHORIZED.getCode(), desc, t);
        return aResultVo;
    }

    /**
     * 参数校验失败
     *
     * @param t
     * @return
     */
    public static <T> AResultVo<T> resultValidateFailed(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.VALIDATE_FAILED.getCode(), ErrorEnum.VALIDATE_FAILED.getDesc(), t);
        return aResultVo;
    }

    public static <T> AResultVo<T> resultValidateFailed(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.VALIDATE_FAILED.getCode(), desc, t);
        return aResultVo;
    }

    public AResultVo<T> validateFailed(T t) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.VALIDATE_FAILED.getCode(), ErrorEnum.VALIDATE_FAILED.getDesc(), t);
        return aResultVo;
    }

    public AResultVo<T> validateFailed(T t, String desc) {
        AResultVo<T> aResultVo = new BaseResultVo<>(ErrorEnum.VALIDATE_FAILED.getCode(), desc, t);
        return aResultVo;
    }

}
